<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    request.setAttribute("basePath",request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath());
%>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
    <style>
        h2{
            margin-left: 283px;
        }
        input{
            width: 603px;
            height: 36px;
            margin-left: 23px;
            border: 1px solid #CFCFCF;
        }
        input[type=button]{
            width: 253px;
            height: 36px;
            margin-left: 93px;
            cursor: pointer;
            border: 1px solid #CFCFCF;
        }
        select{
            width: 605px;
            height: 36px;
            border: 1px solid #CFCFCF;
            margin-left: 23px;
        }
        textarea{
            width: 600px;
            height: 200px;
            border: 1px solid #CFCFCF;
            margin-left: 23px;
        }
        #modes{
            width: 608px;
            height: auto;
            margin-left: 93px;
        }
    </style>
    <title></title>
    <script src="${basePath}/js/jquery-1.5.2.min.js"></script>
    <script type="text/javascript">
        var controllerJson = [
			{"path":"/func_account_imgverify","des":"获取图片验证码"},
			{"path":"/comuser_exregister","des":"用户注册"},
			{"path":"/comacct_alias_mod","des":"昵称修改"},
			{"path":"/combine_basic_info_qry","des":"组合基本信息查询"},
			{"path":"/combine_apply","des":"组合申请"},
			{"path":"/combine_collect","des":"组合关注"},
			{"path":"/combine_collect_cancel","des":"组合关注取消"},
			{"path":"/combine_order_qry","des":"组合排名"},
			{"path":"/combine_apply","des":"组合申请"},
			{"path":"/comentrust_detail_order_enter","des":"个股委托"},
			{"path":"/comentrust_order_enter","des":"组合委托"},
			{"path":"/combine_collect_info_qry","des":"关注的组合"},
			{"path":"/comuser_collect_qry","des":"关注的投顾"},
			{"path":"/combine_focus_info_qry","des":"已订阅的组合"},
			{"path":"/combine_recommend_qry","des":"组合推荐信息查询"},
			{"path":"/combine_focus","des":"组合订阅"},
			{"path":"/combine_focus_cancel","des":"组合订阅取消"},
			{"path":"/combine_his_incomeratio_qry","des":"组合历史收益率"},
			{"path":"/combineclose_apply","des":"组合关闭申请"},
			{"path":"/combine_farearg_qry","des":"组合费用查询"},
			{"path":"/combine_mod_apply","des":"组合信息修改"},
			{"path":"/balancefast_qry","des":"可用资金查询"},
			{"path":"/stock_qry","des":"可用持仓查询"},
			{"path":"/comentrust_detail_qry","des":"当日调仓"},
			{"path":"/comentrust_detail_his_qry","des":"历史调仓"},
			{"path":"/businacct_bind","des":"资金账号绑定"},
			{"path":"/businacct_unbind","des":"资金账号解绑"},
			{"path":"/channel_login","des":"交易登录"},
			{"path":"/comuser_recommend_qry","des":"推荐投顾查询"},
			{"path":"/comadviser_order_qry","des":"投顾排名"},
			{"path":"/comuser_collect","des":"投顾关注"},
			{"path":"/comadviser_qry","des":"投顾详情"},
			{"path":"/comuser_his_incomeratio_qry","des":"投顾历史收益率"},
			{"path":"/extcomdata_notify_qry","des":"消息通知"},
			{"path":"/combine_detail_info_qry","des":"组合成分"},
			{"path":"/comb_his_comentrust","des":"组合历史调仓"},
			{"path":"/comuser_sign","des":"达人签约"},
			{"path":"/comuser_sign_cancel","des":"达人解约"},
			{"path":"/comadviser_sign_qry","des":"达人已签约客户查询"},
            {"path":"/extcomacct_farearg_set","des":"组合费用设置"},
            {"path":"/extcomacct_farearg_qry","des":"组合参数费用查询"},
            {"path":"/comentrust_detail_withdraw_qry","des":"可撤委托明细查询"},
            {"path":"/comentrust_detail_order_withdraw","des":"个股委托撤单"},
            {"path":"/bankfund_qry","des":"存管资金账户资金查询"},
            {"path":"/bktransfer_qry","des":"银行转账日志查询"},
            {"path":"/banktransfer","des":"银行转账"},
            {"path":"/bankbalance_qry","des":"银行余额查询"},
            {"path":"/realtime_qry","des":"当日成交查询"},
            {"path":"/bankaccout_qry","des":"银行账户查询"},
            {"path":"/his_realtime_qry","des":"历史成交查询"},
            {"path":"/almostbuy_qry","des":"大约可买获取"},
            {"path":"/securities_deal_qry","des":"证券成交查询"},
            {"path":"/income_balance_qry","des":"客户盈亏查询"},
            {"path":"/his_com_fundstock_qry","des":"历史资金证券流水查询"},
            {"path":"/his_com_deliver_qry","des":"历史交割信息查询"},
            {"path":"/his_com_secuipoinfo_qry","des":"新股认购信息查询"},
            {"path":"/his_com_matchinfo_nopwdqry","des":"历史配号信息查询"},
            {"path":"/his_com_luckyinfo_nopwdqry","des":"历史中签信息查询"},
            {"path":"/trad_pwd_mod","des":"交易密码修改"},
            {"path":"/comuser_businacct_qry","des":"账户绑定关系查询"},
            {"path":"/compay_apply_qry","des":"支付申请查询"},
            {"path":"/compay_confirm","des":"支付结果通知"},
            {"path":"/compay_identify","des":"支付确认"},
            {"path":"/compay_apply","des":"支付申请"},
            {"path":"/combine_search","des":"组合搜索"},
            {"path":"/comadviser_build","des":"投顾创建"},
            {"path":"/combine_focus_renew","des":"组合关注续费"},
            {"path":"/prodcode_adviser_his_qry","des":"个股关联投顾信息查询"},
            {"path":"/user_adviser_his_qry","des":"用户签约达人历史查询"},
            {"path":"/comentrust_detail_reason_mod","des":"批量个股委托投资依据修改"},
            {"path":"/combine_focus_num_qry","des":"组合订阅客户查询"},
            {"path":"/combine_collect_num_qry","des":"组合收藏客户查询"},
            {"path":"/comadviserteam_qry","des":"投顾团队信息查询"},
            {"path":"/tip_info_qry","des":"支付信息查询"},
            {"path":"/comadviser_bginfo_mod","des":"达人简介信息修改"},
            {"path":"/comuser_sign_qry","des":"用户已签约达人信息查询"},
            {"path":"/extcomacct_vague_qry","des":"投顾模糊搜索"},
            {"path":"/combineapply_query","des":"组合申请查询"},
            {"path":"/extcombine_combinestatus_mod","des":"组合状态设置"},
            {"path":"/adviser_focus_num_qry","des":"投顾订阅查询"},
            {"path":"/adviser_collect_num_qry","des":"投顾收藏查询"},
            {"path":"/comdata_adviserbine_successrate_qry","des":"投顾组合胜率查询"},
            {"path":"/extcombine_combinestatus_mod","des":"投顾组合胜率查询"},
            {"path":"/comuser_relation_num_qry","des":"用户关系汇总查询"},
            {"path":"/extcombine_combine_recommend_cancel","des":"组合推荐取消"},
            {"path":"/extcombine_combine_recommend","des":"组合推荐设置"},
            {"path":"/extcomacct_adviser_recommend_cancel","des":"达人推荐取消"},
            {"path":"/extcomacct_adviser_recommend","des":"达人推荐设置"},
            {"path":"/extcomdata_max_withdrawal_rate_qry","des":"最大回撤率查询"},
            {"path":"/extcomacct_signapply_qry","des":"达人签约申请查询"},
            {"path":"/extcomacct_signrenew_verify","des":"达人签约申请审核通过查询"},
            {"path":"/extcomacct_signrenew_notverify","des":"达人签约申请审核不通过查询"},
            {"path":"/home_comb_rec","des":"组合推荐(首页)"},
            {"path":"/home_comuser_rec","des":"达人推荐(首页)"},
            {"path":"/middle_comb_details","des":"中台组合基本信息查询"},
            {"path":"/extcomacct_rewark_amount_qry","des":"投顾当日剩余允许打赏金额查询"},
            {"path":"/comuser_sign_change","des":"达人改签申请"},
            {"path":"/comuser_sign_change_verify_nopass","des":"达人改签申请审核不通过"},
            {"path":"/comuser_sign_change_verify_pass","des":"达人改签申请审核通过"},
            {"path":"/comuser_sign_record_qry","des":"达人签约记录查询"},
            {"path":"/his_business_qry","des":"历史证券成交查询"},
            {"path":"/comacct_adviser_mod","des":"投顾信息修改"},
            {"path":"/extcomtrade_his_bktransfer_qry","des":"银行转账日志历史查询"},
            {"path":"/ping_plus_pay_apply","des":"ping++支付申请"},
            {"path":"/extcompay_signfocus_apply_qry","des":"订约申请查询"},
            {"path":"/extcompay_comdate_limited_amount_qry","des":"当日单客户允许打赏单投顾剩余金额查询"},
            {"path":"/comadviser_adviserteam_qry","des":"投顾团队归属信息查询"},
            {"path":"/extcomacct_comusersign_verify","des":"达人签约申请审核通过"},
            {"path":"/extcomacct_comusersign_notverify","des":"达人签约申请审核不通过"},
            {"path":"/user_transfer_qry","des":"用户调仓记录查询"},
            {"path":"/comtrade_comblackcode_qry","des":"产品代码黑名单查询"},
            {"path":"/combine_apply_verify","des":"组合申请审核通过"},
            {"path":"/combine_apply_notverify","des":"组合申请审核不通过"},
            {"path":"/combine_apply_qry","des":"投顾组合申请查询"},
            {"path":"/combine_mod_verify","des":"组合信息修改审核通过"},
            {"path":"/combine_mod_notverify","des":"组合信息修改审核不通过"},
            {"path":"/combine_closeapply_verify","des":"组合关闭申请审核通过"},
            {"path":"/combine_close_notverify","des":"组合关闭申请审核不通过"},
            {"path":"/combine_closeapply_qry","des":"投顾组合关闭申请查询"},
            {"path":"/combine_modapply_qry","des":"投顾组合信息修改申请查询"},
            {"path":"/his_securities_commission_qry","des":"历史证券委托查询"},
            {"path":"/talent_sign_apply_qry","des":"中台达人签约申请查询"},
            {"path":"/dongbei_trans_login","des":"东北交易登录"}
        ];
        var accesstoken = "";
        $(function () {
            $("#txtConller").append(new Option("请选择", "", true));
            for (var i = 0; i < controllerJson.length; i++) {
                var option = new Option(controllerJson[i].path+"..."+controllerJson[i].des, controllerJson[i].path);
                $("#txtConller").append(option);
            }

            $("#txtConller").change(function(){
                var path = $(this).val();
                $.ajax({
                    url: "/js/testdata.json",
                    type: "GET",
                    dataType: "json",
                    success: function (data) {
                        for(var p in data){//遍历json对象的每个key/value对,p为key
                            if("/"+p==path){
                            	if(typeof(data[p].user_token) != "undefined"){
	                            	data[p].user_token = accesstoken;
                            	}
                                $("#txtParams").val(format(JSON.stringify(data[p])));
                            }
                        }
                    }
                });
            });
        });

        function btnSubmit() {
            var address = $("#txtUrl").val();
            var controller = $("#txtConller").val();
            var stype = $("#sType").val();
            var params = $("#txtParams").val();
            if (address == "") {
                return false;
            }
            if (controller == "") {
                alert("请求路径不能为空");
                return false;
            }
            if (stype == "") {
                alert("请求行为必填");
                return false;
            }
            if (params == "") {
                params = null;
            }
            if (params != "") {
                params = JSON.parse(params);
            }
            var rURl = address + controller
            $.ajax({
                url: rURl,
                type: stype,
                data: params,
                dataType: "json",
                success: function (data) {
                	if(data.data.user_token){
                		accesstoken = data.data.user_token + "";
                	}
                	if(data.data[0] && data.data[0].user_token){
                		accesstoken = data.data[0].user_token;
                	}
                    document.getElementById("modes").innerHTML = CurentTime()+"<br>"+JSON.stringify(data,null,"<p>");
                }
            }).fail(
                    function (xhr, textStatus, err) {
                        var msg = "";
                        if (err == "") {
                            msg = "<span style='color:red;'>服务端错误或服务未启动！</span>";
                        }
                        else {
                            msg = "<span style='color:red;'>" + err + "!</span>";
                        }
                        document.getElementById("modes").innerHTML = CurentTime()+msg;
                    });
        }

        function btnSubmit2() {
            var address = $("#txtUrl").val();
            var controller = $("#txtConller").val();
            var stype = $("#sType").val();
            var params = $("#txtParams").val();
            if (address == "") {
                return false;
            }
            if (controller == "") {
                alert("请求路径不能为空");
                return false;
            }
            if (stype == "") {
                alert("请求行为必填");
                return false;
            }
            if (params == "") {
                params = null;
            }
            if (params != "") {
                params = JSON.parse(params);
            }
            var rURl = address + controller
            $.ajax({
                url: rURl,
                type: stype,
                data: params,
                dataType: "jsonp",
                async: false,
                jsonp: "jsonpcallback", //服务端用于接收callback调用的function名的参数
                success: function(data) {
                    document.getElementById("modes").innerHTML = CurentTime()+"<br>"+JSON.stringify(data,null,"<p>");
                },
                error: function(xhr, textStatus, err){
                    var msg = "";
                    if (err == "") {
                        msg = "<span style='color:red;'>服务端错误或服务未启动！</span>";
                    }
                    else {
                        msg = "<span style='color:red;'>" + err + "!</span>";
                    }
                    document.getElementById("modes").innerHTML = CurentTime()+msg;
                }
            });
        }
        function CurentTime(){
            var now = new Date();
            var year = now.getFullYear();       //年
            var month = now.getMonth() + 1;     //月
            var day = now.getDate();            //日
            var hh = now.getHours();            //时
            var mm = now.getMinutes();          //分
            var ss = now.getSeconds();          //分
            var clock = year + "-";
            if(month < 10)
                clock += "0";
            clock += month + "-";
            if(day < 10)
                clock += "0";
            clock += day + " ";
            if(hh < 10)
                clock += "0";
            clock += hh + ":";
            if (mm < 10) clock += '0';
            clock += mm + ":";
            if (ss < 10) clock += '0';
            clock += ss;
            return("["+clock+"]");
        }

        function format(txt,compress/*是否为压缩模式*/){/* 格式化JSON源码(对象转换为JSON文本) */
            var indentChar = '    ';
            if(/^\s*$/.test(txt)){
                alert('数据为空,无法格式化! ');
                return;
            }
            try{var data=eval('('+txt+')');}
            catch(e){
                alert('数据源语法错误,格式化失败! 错误信息: '+e.description,'err');
                return;
            };
            var draw=[],last=false,This=this,line=compress?'':'\n',nodeCount=0,maxDepth=0;

            var notify=function(name,value,isLast,indent/*缩进*/,formObj){
                nodeCount++;/*节点计数*/
                for (var i=0,tab='';i<indent;i++ )tab+=indentChar;/* 缩进HTML */
                tab=compress?'':tab;/*压缩模式忽略缩进*/
                maxDepth=++indent;/*缩进递增并记录*/
                if(value&&value.constructor==Array){/*处理数组*/
                    draw.push(tab+(formObj?('"'+name+'":'):'')+'['+line);/*缩进'[' 然后换行*/
                    for (var i=0;i<value.length;i++)
                        notify(i,value[i],i==value.length-1,indent,false);
                    draw.push(tab+']'+(isLast?line:(','+line)));/*缩进']'换行,若非尾元素则添加逗号*/
                }else   if(value&&typeof value=='object'){/*处理对象*/
                    draw.push(tab+(formObj?('"'+name+'":'):'')+'{'+line);/*缩进'{' 然后换行*/
                    var len=0,i=0;
                    for(var key in value)len++;
                    for(var key in value)notify(key,value[key],++i==len,indent,true);
                    draw.push(tab+'}'+(isLast?line:(','+line)));/*缩进'}'换行,若非尾元素则添加逗号*/
                }else{
                    if(typeof value=='string')value='"'+value+'"';
                    draw.push(tab+(formObj?('"'+name+'":'):'')+value+(isLast?'':',')+line);
                };
            };
            var isLast=true,indent=0;
            notify('',data,isLast,indent,false);
            return draw.join('');
        }
    </script>
</head>
<body>
<h2>API 测试页面</h2>
<table border="0" cellpadding="0" cellspacing="5">
    <tr>
        <td>请求地址</td>
        <td>
            <input type="text" value="http://127.0.0.1:21700" name="txtUrl" id="txtUrl" maxlength="200"/></td>
    </tr>
    <tr>
        <td>请求路径</td>
        <td>
            <select id="txtConller" name="txtConller">

            </select>
    </tr>
    <tr>
        <td>请求行为</td>
        <td>
            <select id="sType" name="sType">
                <option value="POST">Post</option>
                <option value="GET">Get</option>
            </select>

        </td>
    </tr>
    <tr>
        <td>请求参数</td>
        <td>
            <textarea value="" cols="50" rows="10" style="overflow: auto;" name="txtParams" id="txtParams" placeholder=' 例如：{"Id":"001","Name":"张三","Phone":"2014/4/22 13:18:26","EmailAddress":"dulei@51lsh.com"}'></textarea>
        </td>
    </tr>
    <tr>

        <td colspan="2">
            <input type="button" value="提 交" onclick="btnSubmit()"/>
            <input type="button" value="跨域提交" onclick="btnSubmit2()"/>
        </td>
    </tr>
</table>
<span>返回数据：</span>

    <div id="modes">

    </div>
</body>
</html>
